package com.ms.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ms.domain.entity.Message;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MessageMapper extends BaseMapper<Message> {

    // 获取用户未读消息数量
    @Select("SELECT COUNT(*) FROM message WHERE user_id = #{userId} AND is_read = 0")
    int countUnreadMessages(@Param("userId") Integer userId);

    // 分页查询用户消息
    @Select("SELECT * FROM message WHERE user_id = #{userId} ORDER BY create_time DESC")
    List<Message> selectMessagesByUserId(@Param("userId") Integer userId);
}
